import Vue from 'vue'
import router from '../router'
import ElementUI from 'element-ui';

import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)

export function jump(name, query){
    router.push({
        name,
        query
    })
}

export function back(){
    router.go(-1)
}

export function toast(index, value){ // index 0: 成功 1：警告 2：信息 3：错误
    ElementUI.Message({
        message: value,
        type: ["success", "warning", "info", "error"][index]
    })
}

export function copy(value){
    if(!value) return ElementUI.Message.error("复制内容为空")
    Vue.prototype.$copyText(value).then(()=>{
        ElementUI.Message.success("复制成功")
    },()=>{
        ElementUI.Message.error("复制失败")
    })
}

export function formatTime(value, type) {
    var dataTime="";
    var data = new Date();
    data.setTime(value);
    var year   =  data.getFullYear();
    var month_temp=data.getMonth()+1;
    var month  =  month_temp<10?'0'+month_temp: month_temp;
    var day    =  data.getDate()<10?'0'+data.getDate(): data.getDate();
    var hour   =  data.getHours()<10?'0'+data.getHours(): data.getHours();
    var minute =  data.getMinutes()<10?'0'+data.getMinutes(): data.getMinutes();
    var second =  data.getSeconds()<10?'0'+data.getSeconds(): data.getSeconds();
    if(type == "YMD"){
        dataTime =  year + "-"+ month + "-" + day;
    }else if(type == "YMDHMS"){
        dataTime = year + "-"+month + "-" + day + " " +hour+ ":"+minute+":" +second;
    }else if(type == "HMS"){
        dataTime = hour+":" + minute+":" + second;
    }else if(type == "YM"){
        dataTime = year + "-" + month;
    }
    return dataTime;//将格式化后的字符串输出到前端显示
}